#include "widget.h"
#include "ui_widget.h"

#include <QRegExpValidator>
#include <QMessageBox>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->line_user->setToolTip("只允许数字0-9且长度为11位");
    QRegExpValidator *userReg = new QRegExpValidator(QRegExp("[0-9]{11}"));
    ui->line_user->setValidator(userReg);

    ui->line_pwd->setToolTip("只允许字母和数字");
    QRegExpValidator *pwdReg = new QRegExpValidator(QRegExp("[a-zA-Z0-9]+$"));
    ui->line_pwd->setValidator(pwdReg);

    QRegExpValidator *emailReg = new QRegExpValidator(QRegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"));
    ui->line_email->setValidator(emailReg);



    connect(ui->btn_submit, &QPushButton::clicked, [ = ]() {
        int pos=0;
        QString user=ui->line_user->text();
        QString pwd=ui->line_pwd->text();
        QString email=ui->line_email->text();
        if (userReg->validate(user,pos) != QValidator::Acceptable ||
                pwdReg->validate(pwd,pos) != QValidator::Acceptable ||
                emailReg->validate(email,pos) != QValidator::Acceptable)
        {
            QMessageBox::information(this,"提示框","提交成功");
        }
        else
        {
            QMessageBox::warning(this,"错误","提交失败");
        }


    });
}

Widget::~Widget()
{
    delete ui;
}
